#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: zzll0909
# @file: 509.py
# @time: 2025/2/5
# @software: PyCharm

class Solution:
    def fib(self, n: int) -> int:
        result = 0
        # 斐波那契数列的前两个数
        if n == 0 or n == 1:
            result = n
        else:
            # 初始化前两个数
            prev = 0
            curr = 1
            # 循环计算第n个斐波那契数
            for i in range(2, n + 1):
                next = prev + curr
                prev = curr
                curr = next
            # 当前值为第n个斐波那契数
            result = curr
        return result


if __name__ == "__main__":
    pass
